package org.csu.mall.controller.front;

import org.csu.mall.common.CONSTANT;
import org.csu.mall.common.UniformResponse;
import org.csu.mall.entity.Category;
import org.csu.mall.service.ICategoryService;
import org.csu.mall.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/category/")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @GetMapping("get_category")
    @ResponseBody
    public UniformResponse<List<CategoryVO>> getChildrenCategory(
            @RequestParam(name = "categoryId", defaultValue = CONSTANT.ALL_CATEGORY) String categoryId){
        return categoryService.getChildrenCategory(categoryId);
    }

    @GetMapping("get_all_category")
    @ResponseBody
    public UniformResponse<List<CategoryVO>> getAllChildrenCategory(
            @RequestParam(name = "categoryId", defaultValue = CONSTANT.ALL_CATEGORY) String categoryId){
        return categoryService.getAllChildrenCategory(categoryId);
    }

    @PostMapping("add_category")
    @ResponseBody
    public UniformResponse<String> addCategory(Category category){
        return categoryService.addCategory(category);
    }

    @PostMapping("update_category")
    @ResponseBody
    public UniformResponse<String> updateCategory(Category category){
        return categoryService.updateCategory(category);
    }

    @GetMapping("cancel_category")
    @ResponseBody
    public UniformResponse<String> cancelCategory(String categoryId){
        return categoryService.cancelCategory(categoryId);
    }
}
